package com.dime.basic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.dime.basic.api.domain.DimeBaseharm;
import com.dime.basic.api.model.ComboBase;
import com.dime.basic.api.model.DimeBasicDataResult;
import com.dime.basic.api.model.HarmType;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.dime.basic.service.IDimeBaseharmService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 危害因素管理Controller
 *
 * @author Tiny
 * @date 2023-09-13
 */
@RestController
@RequestMapping("/baseharm")
public class DimeBaseharmController extends BaseController
{
    @Autowired
    private IDimeBaseharmService dimeBaseharmService;

    /**
     * 查询危害因素管理列表
     */
   // @RequiresPermissions("basic:baseharm:list")
    @GetMapping("/list")
    public TableDataInfo list(DimeBaseharm dimeBaseharm)
    {
        startPage();
        List<DimeBaseharm> list = dimeBaseharmService.selectDimeBaseharmList(dimeBaseharm);
        return getDataTable(list);
    }

    /**
     * 导出危害因素管理列表
     */
    @RequiresPermissions("basic:baseharm:export")
    @Log(title = "危害因素管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DimeBaseharm dimeBaseharm)
    {
        List<DimeBaseharm> list = dimeBaseharmService.selectDimeBaseharmList(dimeBaseharm);
        ExcelUtil<DimeBaseharm> util = new ExcelUtil<DimeBaseharm>(DimeBaseharm.class);
        util.exportExcel(response, list, "危害因素管理数据");
    }

    /**
     * 获取危害因素管理详细信息
     */
    @RequiresPermissions("basic:baseharm:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dimeBaseharmService.selectDimeBaseharmById(id));
    }

    /**
     * 新增危害因素管理
     */
    @RequiresPermissions("basic:baseharm:add")
    @Log(title = "危害因素管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DimeBaseharm dimeBaseharm)
    {
        return toAjax(dimeBaseharmService.insertDimeBaseharm(dimeBaseharm));
    }

    /**
     * 修改危害因素管理
     */
    @RequiresPermissions("basic:baseharm:edit")
    @Log(title = "危害因素管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DimeBaseharm dimeBaseharm)
    {
        return toAjax(dimeBaseharmService.updateDimeBaseharm(dimeBaseharm));
    }

    /**
     * 删除危害因素管理
     */
    @RequiresPermissions("basic:baseharm:remove")
    @Log(title = "危害因素管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dimeBaseharmService.deleteDimeBaseharmByIds(ids));
    }


    @GetMapping("/info/allharmtypes")
    public R<List<HarmType>> getallharmtype()
    {
        List<HarmType> list = dimeBaseharmService.selectAllHarmsGroupbyHarmType();
        return R.ok(list);
    }

    @GetMapping("/info/harm/{harmcode}")
    public R<DimeBaseharm> getharmbycode(@PathVariable String harmcode)
    {
        DimeBaseharm harm = dimeBaseharmService.selectHarmByCode(harmcode);
        return R.ok(harm);
    }
    @GetMapping("/info/harms/{harmcodes}")
    public R<List<DimeBaseharm>> getharmsbycodes(@PathVariable String[] harmcodes)
    {
        List<DimeBaseharm> harm = dimeBaseharmService.selectHarmsByCodes(harmcodes);
        return R.ok(harm);
    }
    @GetMapping("/info/harmsByIds/{ids}")
    public R<List<DimeBaseharm>> getharmbyids(@PathVariable String[] ids)
    {
        List<DimeBaseharm> harm = dimeBaseharmService.selectHarmsByIds(ids);
        return R.ok(harm);
    }
}
